// SPDX-License-Identifier: GPL-2.0
/*
 * WORKQUEUE STALLS
 *
 * (C) 2024.05.19 BiscuitOS <buddy.zhang@aliyun.com>
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/workqueue.h>
#include <linux/kthread.h>

static struct workqueue_struct *wq;
static struct work_struct work;

static void work_fn(struct work_struct *work)
{
	printk("START KTHREAD.\n");
	while (!kthread_should_stop()) {
		/* OCCUPY CPU */
		cpu_relax();
	}
}

static int __init BiscuitOS_init(void)
{
	/* CREATE WORKQUEUE */
	wq = create_singlethread_workqueue("BiscuitOS-WQ");
	if (!wq)
		return -EINVAL;

	/* INIT WORK */
	INIT_WORK(&work, work_fn);

	/* COMMIT WORK INTO WORKQUEUE */
	queue_work(wq, &work);

	return 0;
}

static void __exit BiscuitOS_exit(void) { }

module_init(BiscuitOS_init);
module_exit(BiscuitOS_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("BiscuitOS <buddy.zhang@aliyun.com>");
MODULE_DESCRIPTION("BiscuitOS OOPS");
